<?php

$destid = $_POST['destid'];
$packid = $_POST['packageid'];

if (isset($_POST['sortfield']))
    $sortfield = $_POST['sortfield'];
else
    $sortfield = 0;

if (isset($_POST['label']))
    $cityid = $_POST['label'];
else
    $cityid = 1;


//if ($label != '') {
//    include_once 'inc/directconn.php';
//    $rs = mysql_query("select id from ats_city where city='$label'")
//        or die('query err');
//
//    $cityrow = mysql_fetch_row($rs);
//    $selectedcityid = $cityrow[0];
//}

include('inc/init.php');
$smarty->assign('title', $title);

$id = -1;
if (isset($_GET['id']))
    $id = $_GET['id'];

$smarty->template_dir = 'templates';

$orderby = " order by ";

switch ($sortfield) {
    case 0:
        //special offer
        $orderby .= "isspecialoffer desc";
        break;
    case 1:
        //lower price
        $orderby .= "pricestart";
        break;
    case 2:
        //alphabet
        $orderby .= "title";
        break;
//    default:
//        if ($label != '') {
//            $pos = strripos($label, ' ');
//            if ($pos > 0) {
//                $pot = substr($label, $pos - strlen($label)+1);
//                
//                include_once 'inc/directconn.php';
//                $rs = mysql_query("select id from ats_city where city='$pot'")
//                    or die('query err');
//                
//                $cityrow = mysql_fetch_row($rs);
//                $orderby .= "cityid=".$cityrow[0]." desc";
//            }
//        }
//        break;
}

$sql = "select * from ats_package where dest_id='" . $destid . "' and cat_id='" . $packid . "' and cityid='" . $cityid . "'" . $orderby;

$packages = $db->prepare($sql);
$packages->execute();
$packages->setFetchMode(PDO::FETCH_ASSOC);


$sql = "select * from ats_package_category where id='" . $packid . "'";
$cat = $db->prepare($sql);
$cat->execute();
$cat->setFetchMode(PDO::FETCH_ASSOC);

$smarty->assign('packages', $packages);
$smarty->assign('cat', $cat);

$smarty->display('getpackages.tpl');
?>